package com.jzo2o.trade.controller;

import com.jzo2o.api.trade.dto.response.ExecutionResultResDTO;
import com.jzo2o.trade.service.IRefundService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * \* User: chy
 * \* Date: 2025/10/9  9:23
 * \* Description:退款服务
 * \
 */
@RestController
@RequestMapping("/inner/refund-record")
public class RefundController {

    @Resource
    private IRefundService refundService;

    /***
     * 统一收单交易退款接口
     * 当交易发生之后一段时间内，由于买家或者卖家的原因需要退款时，卖家可以通过退款接口将支付款退还给买家，
     * 将在收到退款请求并且验证成功之后，按照退款规则将支付款按原路退到买家帐号上。
     * @param tradingOrderNo 支付单号
     * @param refundAmount 退款金额
     * @return
     */
    @PostMapping("/refund")
    public ExecutionResultResDTO refund(@RequestParam("tradingOrderNo") Long tradingOrderNo,
                                        @RequestParam("refundAmount") BigDecimal refundAmount) {

        return refundService.refundTrading(tradingOrderNo, refundAmount);
    }
}
